package com.mkyong.client;

import java.awt.Graphics;
import java.awt.Image;
import java.awt.image.BufferedImage;

import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

import javax.imageio.ImageIO;

import javax.sound.sampled.AudioInputStream;
import javax.swing.JPanel;
import javax.xml.namespace.QName;
import javax.xml.ws.Service;

import sun.audio.AudioData;
import sun.audio.AudioDataStream;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;

import com.mkyong.entity.Alphabet;
import com.mkyong.ws.HelloWorld;

class Panneau extends JPanel {
	BufferedImage image;
	
	public Panneau() {
		URL url = null;
		try {
			url = new URL("http://localhost:8080/ws/hello?wsdl");
		} catch (MalformedURLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

		// 1st argument service URI, refer to wsdl document above
		// 2nd argument is service name, refer to wsdl document above
		QName qname = new QName("http://ws.mkyong.com/",
				"HelloWorldImplService");

		Service service = Service.create(url, qname);

		HelloWorld hello = service.getPort(HelloWorld.class);
		 Alphabet alpahbet = hello.getAlphabet();
		byte[] bytes = alpahbet.getImages().get(0);
		ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
			
				
				
				try {
					image = ImageIO.read(bis);
					AudioData audiodata = new AudioData(alpahbet.getSons().get(0));
					AudioDataStream audioStream = new AudioDataStream(audiodata);
					AudioPlayer.player.start(audioStream);
				} catch (IOException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} // the image is read in

				// store it back again as a file

			

			
		
	
	}

	public void paintComponent(Graphics g) {
		super.paintComponent(g);
		int x = 20, y = 20;
		if (image != null) {
			g.drawImage(image, x, y, this);
			
		}
	}

	
}